import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Material
WQRectangle {
    id:rect
    property Component nonClientArea
    //property Component systemBar
    property var title 
    property var active
    radius: WQTheme.macOS?"10,10,0,0":"0,0,0,0"
    MouseArea {
        anchors.fill: parent
        // 鼠标点击事件
        onPressed: function(mouse){
            // 记下鼠标当前坐标，并标识拖动状态为 true
            if (mouse.button === Qt.LeftButton) {
                window.startSystemMove()
            }
        }
        // 双击切换最大化/恢复
        onDoubleClicked: function(mouseEvent) {
            if (mouseEvent.button === Qt.LeftButton) {
                if (window.visibility === Window.Maximized)
                    window.showNormal();
                else
                    window.showMaximized();
            }
        }
    }
    Component{
        id: macSystemBar
        MacSystemBar{

        }
    }
    Component{
        id: windowSystemBar
        WindowSystemBar{

        }
    }
    Row {
        id:row
        //leftPadding:  8
        layoutDirection: WQTheme.macOS ? Qt.LeftToRight: Qt.RightToLeft
        leftPadding: WQTheme.macOS ? 8 : 0
        Loader {
            id: systemBar
            width:systemBar.implicitWidth
            height: rect.height
            sourceComponent: WQTheme.macOS ? macSystemBar : windowSystemBar
            // Component.onCompleted: {
            //     console.log("systemBar Component.onCompleted,Qt.platform.os,x,y,width,height=",Qt.platform.os,x,y,width,height)
            //     var bar  = Qt.createComponent(WQTheme.macOS ? "MacSystemBar.qml" : "WindowSystemBar.qml")
            //     systemBar.sourceComponent = bar
            //     if(!WQTheme.macOS){
            //         row.leftPadding = 0
            //         row.layoutDirection = Qt.RightToLeft
            //     }
            // }
        }
        Loader {
            x: systemBar.width
            id: nonClientArea
            width: rect.width - systemBar.width
            height: rect.height
            sourceComponent: rect.nonClientArea
            Component.onCompleted: {
                console.log("nonClientArea Component.onCompleted,x,y,width,height=",x,y,width,height)
            }
        }       
    }
    Component.onCompleted: {
        console.log("WQSystemBar Component.onCompleted,x,y,width,height=",x,y,width,height)
        rect.y = 0
    }
}